文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
- Brute Force
1 | class Solution { |
- Two Pointer Approach
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17class Solution {
public:
int maxArea(vector<int>& height) {
int i = 0;
int j = height.size() - 1;
int maxArea = 0;
int area = 0;
while(i < j) {
area = (j - i) * (height[i]<height[j]?height[i]:height[j]);
if(maxArea < area) {
maxArea = area;
}
height[i]<height[j]?i++:j--;
}
return maxArea;
}
};